package com.property.biz.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.property.biz.CommunityBiz;
import com.property.dao.CommunityDao;
import com.property.dao.ComplaintDao;
import com.property.dao.DisposeDao;
import com.property.dao.InformDao;
import com.property.dao.InformTargetDao;
import com.property.dao.LrrelationDao;
import com.property.dao.ManagementDao;
import com.property.dao.OwnerDao;
import com.property.dao.UserDao;
import com.property.entity.Community;
import com.property.entity.Management;

@Service("communityBiz")
@Scope("prototype")
public class CommunityBizImpl implements CommunityBiz {
	@Autowired
	private CommunityDao communityDao;
	@Autowired
	private InformTargetDao informTargetDao;
	@Autowired
	private InformDao informDao;
	@Autowired
	private DisposeDao disposeDao;
	@Autowired
	private ComplaintDao complaintDao;
	@Autowired
	private LrrelationDao lrrelationDao;
	@Autowired
	private OwnerDao ownerDao;
	@Autowired
	private ManagementDao managementDao;
	@Autowired
	private UserDao UserDao;

	public List<Community> getAll() {

		return communityDao.getAll();
	}

	public Community getById(int id) {
		return communityDao.getById(id);
	}

	public void addCommunity(Community community) {
		communityDao.addCommunity(community);
	}

	public void updateCommun(Community community) {
		communityDao.updateCommun(community);
	}

	public List<Community> getList() {

		return communityDao.getList();
	}

	public void delCommunity(int cid) {
		// 通知
		informTargetDao.delInform(cid);
		informDao.delInform(cid);
		// 报修投诉
		disposeDao.delDispose(cid);
		complaintDao.delComplaint(cid);
		// 权限
		lrrelationDao.delManagementLimit(cid);
		// 业主
		ownerDao.delOwner(cid);
		// 物管
		List<Management> managements = managementDao.getUserId(cid);
		managementDao.delManagement(cid);
		for (Management management : managements) {
			UserDao.delUserManage(management.getUser().getId());
		} // 小区
		communityDao.delCommunity(cid);
	}

	public void updateCommunity(Community community) {
		communityDao.updateCommunity(community);

	}

}
